<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <div id="box"></div>
    <button id="btn">抽奖</button>
  </body>
  <script>
    // function draw(first = 1, second = 3, third = 5) {
    //   let firstPirze = ['媳妇', '冰箱', '跑车', '飞机', '别墅', '别人的媳妇']
    //   let setcondPrize = ['2A', '2B', '2C', '2D', '2E', '2F', '2G', '2h']
    //   let thirdPrize = [
    //     '3A',
    //     '3B',
    //     '3C',
    //     '3D',
    //     '3E',
    //     '3F',
    //     '3G',
    //     '3H',
    //     '3K',
    //     '3L'
    //   ]
    //   var result = [] //放奖品的数组
    //   var random //每次随机数
    //   // 一等奖
    //   for (let i = 0; i < first; i++) {
    //     random = Math.floor(Math.random() * firstPirze.length) //下标
    //     result = result.concat(firstPirze.splice(random, 1))
    //   }
    //   // 二等奖
    //   for (let i = 0; i < second; i++) {
    //     random = Math.floor(Math.random() * setcondPrize.length) //下标
    //     result = result.concat(setcondPrize.splice(random, 1))
    //   }
    //   // 二等奖
    //   for (let i = 0; i < third; i++) {
    //     random = Math.floor(Math.random() * thirdPrize.length) //下标
    //     result = result.concat(thirdPrize.splice(random, 1))
    //   }
    //   return result
    // }
    // console.log(draw())

    function* draw(first = 1, second = 3, third = 5) {
      let firstPirze = ['媳妇', '10亿现金', '跑车', '飞机', '别墅']
      let setcondPrize = ['2A', '2B', '2C', '2D', '2E', '2F', '2G', '2h']
      let thirdPrize = [
        '3A',
        '3B',
        '3C',
        '3D',
        '3E',
        '3F',
        '3G',
        '3H',
        '3K',
        '3L'
      ]
      var result = [] //放奖品的数组
      var count = 0 //抽奖次数
      while (1) {
        if (count < first) {
          random = Math.floor(Math.random() * firstPirze.length) //下标
          yield firstPirze.splice(random, 1)
          count++
        } else if (count < first + second) {
          random = Math.floor(Math.random() * setcondPrize.length) //下标
          yield setcondPrize.splice(random, 1)
          count++
        } else if (count < first + second + third) {
          random = Math.floor(Math.random() * thirdPrize.length) //下标
          yield thirdPrize.splice(random, 1)
          count++
        } else {
          return false
        }
      }
    }

    // g.next().value
    var btn = document.getElementById('btn')
    var d = draw()
    btn.onclick = function() {
      var box = document.getElementById('box')
      let str = ``
      var prize = d.next().value
      str += `恭喜获得：${prize} #######`
      box.innerHTML = str
    }
  </script>
</html>
